Float, double, and decimal *practically* do the same thing.
If you're concerned with accuracy and don't care about performance, use decimal.
If you want speed and don't mind *minor* inaccuracies in calculations, use either float or double.
String (string): holds unicode data.
Example: string foobar = "This is a string";
What the hell does all this mean??
Chill! Odds are you'll never need (or want) to know/understand everything I said on this page.
The important things to take away from this are as follows:
If you're playing with whole numbers (that is, things that don't have decimals), then the int datatype is your friend.
If you're handling things that contain decimals, then you'll want to use one of the float, double, or decimal datatypes.
See my notes above to help you figure which is best in your situation.
If you're handling things with letters, you'll obviously be dealing with strings and thus need to use the string datatype.
Extra important:
This should go without saying, but I'm saying it anyway -- you CANNOT perform mathematical operations on non-similar datatypes. That is to say, that you cannot take the string "Kittens" and try to multiply it by the int "2"; trust me, bad things will happen.
This is especially important when dealing with *user input* as while input may look like an integer/decimal/float/double, it can (and probably will be) a string!
Example (this will not work as it is attempting to perform math on unlike types):
string foobar = "2"; int barbaz = 2; int foobaz = foobar + barbaz;
To overcome this, you must first cast/convert the string foobar to an integer.
string foobar = "2"; int barbaz = 2; int foobaz = Convert.ToInt32(foobar) + barbaz;
Integer (int): can be signed (int) or unsigned (uint); whole numbers only (32-bit signed/unsigned).
Float (float): holds floating-point values; decimals or whole numbers (32-bit signed).
- Example: float foobaz = 1.234;
Double (double): holds floating-point values; decimals or whole numbers (64-bit signed).- Example: double barbaz = 1.234;
Decimal (decimal): holds floating-point values; decimals or whole numbers (128-bit signed).String (string): holds unicode data.
What the hell does all this mean??
Chill! Odds are you'll never need (or want) to know/understand everything I said on this page.
The important things to take away from this are as follows:
Extra important:
This should go without saying, but I'm saying it anyway -- you CANNOT perform mathematical operations on non-similar datatypes. That is to say, that you cannot take the string "Kittens" and try to multiply it by the int "2"; trust me, bad things will happen.This is especially important when dealing with *user input* as while input may look like an integer/decimal/float/double, it can (and probably will be) a string!
Example (this will not work as it is attempting to perform math on unlike types):
string foobar = "2";
int barbaz = 2;
int foobaz = foobar + barbaz;
To overcome this, you must first cast/convert the string foobar to an integer.
string foobar = "2";
int barbaz = 2;
int foobaz = Convert.ToInt32(foobar) + barbaz;
See this list from Microsoft for more information on the Convert method: http://msdn.microsoft.com/en-us/library/system.convert_methods.aspx